import request from '@/utils/request'
import type {
  categoryListResponseData,
  AttrResponseData,
  Attr
} from '@/api/product/attr/type'

enum Api {
  GET_CATEGORY1 = '/admin/product/getCategory1',
  GET_CATEGORY2 = '/admin/product/getCategory2',
  GET_CATEGORY3 = '/admin/product/getCategory3',
  GET_ATTR_LIST = '/admin/product/attrInfoList',
  ADD_OR_UPDATE_ATTR = '/admin/product/saveAttrInfo',
  DELETE_ATTR = '/admin/product/deleteAttr'
}

export const reqGetCategory1 = () =>
  request.get<any, categoryListResponseData>(Api.GET_CATEGORY1)
export const reqGetCategory2 = (category1Id: string | number) =>
  request.get<any, categoryListResponseData>(
    Api.GET_CATEGORY2 + `/${category1Id}`
  )
export const reqGetCategory3 = (category2Id: string | number) =>
  request.get<any, categoryListResponseData>(
    Api.GET_CATEGORY3 + `/${category2Id}`
  )
export const reqGetAttrList = (
  category1Id: string | number,
  category2Id: string | number,
  category3Id: string | number
) =>
  request.get<any, AttrResponseData>(
    Api.GET_ATTR_LIST + `/${category1Id}/${category2Id}/${category3Id}`
  )
export const reqAddOrUpdateAttr = (data: Attr) =>
  request.post<any, any>(Api.ADD_OR_UPDATE_ATTR, data)
export const reqDeleteAttr = (attrId: string | number) =>
  request.delete<any, any>(Api.DELETE_ATTR + `/${attrId}`)
